﻿<%@ Page Title="Sico Mill" Language="C#" MasterPageFile="~/TableMaster.master" AutoEventWireup="true" CodeFile="SicoMill.aspx.cs" Inherits="Pages_SicoMill" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">

    <style>
        @media only screen and (max-width: 760px), (min-device-width: 768px) and (max-device-width: 1024px) {

            .resTbl tr:nth-of-type(odd) {
                background-color: #CDE2FF;
            }

            .resTbl tr:nth-of-type(1) {
                display: none;
            }

            .resTbl td:nth-of-type(1):before {
                content: "PO Number ";
            }

            .resTbl td:nth-of-type(2):before {
                content: "Work Order # ";
            }

            .resTbl td:nth-of-type(3):before {
                content: "Total Input RM Si (in Kg) ";
            }

            .resTbl td:nth-of-type(4):before {
                content: "Mill Selection ";
            }

            .resTbl td:nth-of-type(5):before {
                content: "Rotor RPM ";
            }

            .resTbl td:nth-of-type(6):before {
                content: "Gas Pressure ";
            }

            .resTbl td:nth-of-type(7):before {
                content: "Feed rate ";
            }

            .resTbl td:nth-of-type(8):before {
                content: "Total Output Product  ";
            }

            .resTbl td:nth-of-type(9):before {
                content: "Date  ";
            }

            .resTbl td:nth-of-type(10):before {
                content: "Created By";
            }

            .resTbl td:nth-of-type(11):before {
                content: "Created Date";
            }
        }
    </style>

    <script language="javascript" type="text/javascript">



        $(document).ready(function () {
            $('#MainContent_Add_ddlPO_Number').on('change', function () {
                executeScalar(this, 'getNextWorkOrderNumber', 'MainContent_Add_txtWork_Order_Number');
                $('#MainContent_Add_txtWork_Order_Number').prop('disabled', true);
            });
        });


        function save() {
            var PO_Number = $('#MainContent_Add_ddlPO_Number').val();
            var Work_Order_Number = $('#MainContent_Add_txtWork_Order_Number').val();
            var Total_Input_RM_Si = $('#MainContent_Add_txtTotal_Input_RM_Si').val();
            var Mill_Selection = $('#MainContent_Add_ddlMill_Selection').val();
            var Rotor_RPM = $('#MainContent_Add_txtRotor_RPM').val();
            var Gas_Pressure = $('#MainContent_Add_txtGas_Pressure').val();
            var Feed_rate = $('#MainContent_Add_txtFeed_rate').val();
            var Total_Output_Product = $('#MainContent_Add_txtTotal_Output_Product').val();
            var Date = $('#MainContent_Add_txtDate').val();
            var Baginput = $('#MainContent_Add_ddlBag_Drum_Input').val();
            var BaginputNum = $('#MainContent_Add_txtBag_Drum_Input_Num').val();
            var Druminput = $('#MainContent_Add_ddlBag_Drum_Output').val();
            var DruminputNum = $('#MainContent_Add_txtBag_Drum_Output_Num').val();

            if (PO_Number == "0") {
                alert('Please Select PO Number');
                return;
            }
            if (Work_Order_Number == "") {
                alert('Please enter Work Order Number');
                return;
            }
            if (Total_Input_RM_Si == "") {
                alert('Please enter Total Input RM SI');
                return;
            }
            if (Mill_Selection == "0") {
                alert('Please Select Mill Selection');
                return;
            }
            if (Rotor_RPM == "") {
                alert('Please enter Rotor RPM');
                return;
            }
            if (Gas_Pressure == "") {
                alert('Please enter Gas Pressure ');
                return;
            }
            if (Feed_rate == "") {
                alert('Please enter Feed rate');
                return;
            }
            if (Total_Output_Product == "") {
                alert('Please enter Total Output Product');
                return;
            }
            if (Date == "") {
                alert('Please enter Date');
                return;
            }
            if (Baginput == "0") {
                alert('Please Select Bag or Drum');
                return;
            }
            if (BaginputNum == "") {
                alert('Please enter Bag or Drum Number');
                return;
            }
            if (Druminput == "0") {
                alert('Please Select Bag or Drum');
                return;
            }
            if (DruminputNum == "") {
                alert('Please enter Bag or Drum Number');
                return;
            }
            var inputVessels = 0;
            var outputVessels = 0;

            var iv_inputs = ["MainContent_Add_ddlBag_Drum_Input", "MainContent_Add_txtBag_Drum_Input_Num"];
            var iv_Fields = ["DRUM_BAG", "DRUM_BAG_Number"];

            var ov_inputs = ["MainContent_Add_ddlBag_Drum_Output", "MainContent_Add_txtBag_Drum_Output_Num"];
            var ov_Fields = ["DRUM_BAG", "DRUM_BAG_Number"];
            var editurl = (window.location.search).split('=');
            var Id = editurl[editurl.length - 1];
            if (Id == "") {
                var json = "[";
                json = "{";
                json += '"PO_Number"' + ':' + '"' + PO_Number + '"';
                json += ',"Work_Order_Number"' + ':' + '"' + Work_Order_Number + '"';
                json += ',"Total_Input_RM_Si"' + ':' + '"' + Total_Input_RM_Si + '"';
                json += ',"Mill_Selection"' + ':' + '"' + Mill_Selection + '"';
                json += ',"Rotor_RPM"' + ':' + '"' + Rotor_RPM + '"';
                json += ',"Gas_Pressure"' + ':' + '"' + Gas_Pressure + '"';
                json += ',"Feed_rate"' + ':' + '"' + Feed_rate + '"';
                json += ',"Total_Output_Product"' + ':' + '"' + Total_Output_Product + '"';
                json += ',"Date"' + ':' + '"' + Date + '"';
                json += ',"sicomill_inputvessels"' + ':' + getValues('mytable1', iv_Fields, iv_inputs);
                json += ',"sicomill_outputvessels"' + ':' + getValues('mytable2', ov_Fields, ov_inputs);

                json += "}";
                //json += "]";

                saveJSonArrays(json, 'save_sicoMill');
            } else {

                var json = "[";
                json = "{";
                json += '"ID"' + ':' + '"' + Id + '"';
                json += ',"PO_Number"' + ':' + '"' + PO_Number + '"';
                json += ',"Work_Order_Number"' + ':' + '"' + Work_Order_Number + '"';
                json += ',"Total_Input_RM_Si"' + ':' + '"' + Total_Input_RM_Si + '"';
                json += ',"Mill_Selection"' + ':' + '"' + Mill_Selection + '"';
                json += ',"Rotor_RPM"' + ':' + '"' + Rotor_RPM + '"';
                json += ',"Gas_Pressure"' + ':' + '"' + Gas_Pressure + '"';
                json += ',"Feed_rate"' + ':' + '"' + Feed_rate + '"';
                json += ',"Total_Output_Product"' + ':' + '"' + Total_Output_Product + '"';
                json += ',"Date"' + ':' + '"' + Date + '"';
                json += ',"sicomill_inputvessels"' + ':' + getValues('mytable1', iv_Fields, iv_inputs);
                json += ',"sicomill_outputvessels"' + ':' + getValues('mytable2', ov_Fields, ov_inputs);

                json += "}";
                //json += "]";

                saveJSonArrays(json, 'update_sicoMill');
                var urlredirect = "http://" + window.location.host + window.location.pathname;
                top.location = urlredirect;
            }


        }


    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="FeaturedContent" runat="Server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="Add" runat="Server">


    <asp:Panel ID="pnlAdd" runat="server">

        <table cellpadding="0" cellspacing="0" style="width: 100%;">

            <tr>
                <td style="width: 200px">
                    <asp:Label ID="lblPO_Number" runat="server" AssociatedControlID="ddlPO_Number" Text="PO Number :"></asp:Label>
                </td>
                <td>
                    <asp:DropDownList ID="ddlPO_Number" runat="server" DataSourceID="Ds_PO_NUM" DataTextField="PURCHASE_ORDER_NO" DataValueField="PURCHASE_ORDER_NO" OnDataBound="ddlPO_Number_DataBound"></asp:DropDownList>
                    <asp:ObjectDataSource ID="Ds_PO_NUM" runat="server" SelectMethod="selectAll" TypeName="DAL_tbl_purchase_order"></asp:ObjectDataSource>
                </td>
            </tr>

            <tr>
                <td style="width: 200px">
                    <asp:Label ID="lblWork_Order_Number" runat="server" AssociatedControlID="txtWork_Order_Number" Text="Work Order # :"></asp:Label>
                </td>
                <td>
                    <asp:TextBox ID="txtWork_Order_Number" runat="server"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <button type="button" class="btn btn-default btn-xs" onclick="addRow('mytable1');"><span class="glyphicon glyphicon-plus"></span>Add Row</button>
                    <table id="mytable1" cellpadding="0" cellspacing="0">
                        <tr>
                            <td style="width: 170px">
                                <asp:Label ID="lblBag_Drum_Input" runat="server" AssociatedControlID="ddlBag_Drum_Input" Text="DRUM/BAG"></asp:Label>
                            </td>
                            <td>
                                <asp:Label ID="lblBag_Drum_Input_Num" runat="server" AssociatedControlID="txtBag_Drum_Input_Num" Text="DRUM/BAG #"></asp:Label>
                            </td>
                            <td></td>
                        </tr>
                        <tr>
                            <td style="width: 170px">
                                <asp:DropDownList ID="ddlBag_Drum_Input" runat="server" DataSourceID="Ds_Bag_Drum" DataTextField="VESSEL_TYPE" DataValueField="VESSEL_ID" OnDataBound="ddlBag_Drum_Input_DataBound">
                                </asp:DropDownList>
                                <asp:ObjectDataSource ID="Ds_Bag_Drum" runat="server" SelectMethod="selectAll" TypeName="DAL_tbl_vessel_master"></asp:ObjectDataSource>
                            </td>
                            <td>
                                <asp:TextBox ID="txtBag_Drum_Input_Num" runat="server"></asp:TextBox>
                            </td>
                            <td>
                                <button type="button" class="btn btn-default btn-xs" onclick="removeRow(this);"><span class="glyphicon glyphicon-remove"></span></button>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>

            <tr>
                <td style="width: 200px">
                    <asp:Label ID="lblTotal_Input_RM_Si" runat="server" AssociatedControlID="txtTotal_Input_RM_Si" Text="Total Input RM Si (in Kg) :"></asp:Label>
                </td>
                <td>
                    <asp:TextBox ID="txtTotal_Input_RM_Si" runat="server"></asp:TextBox>
                </td>
            </tr>

            <tr>
                <td style="width: 200px">
                    <asp:Label ID="lblMill_Selection" runat="server" AssociatedControlID="ddlMill_Selection" Text="Mill Selection :"></asp:Label>
                </td>
                <td>
                    <asp:DropDownList ID="ddlMill_Selection" runat="server" DataSourceID="Ds_Mills" DataTextField="MILL_TYPE" DataValueField="MILL_ID" OnDataBound="ddlMill_Selection_DataBound"></asp:DropDownList>
                    <asp:ObjectDataSource ID="Ds_Mills" runat="server" SelectMethod="selectAll" TypeName="DAL_tbl_mills_master"></asp:ObjectDataSource>
                </td>
            </tr>

            <tr>
                <td style="width: 200px">
                    <asp:Label ID="lblRotor_RPM" runat="server" AssociatedControlID="txtRotor_RPM" Text="Rotor RPM :"></asp:Label>
                </td>
                <td>
                    <asp:TextBox ID="txtRotor_RPM" runat="server"></asp:TextBox>
                </td>
            </tr>

            <tr>
                <td style="width: 200px">
                    <asp:Label ID="lblGas_Pressure" runat="server" AssociatedControlID="txtGas_Pressure" Text="Gas Pressure :"></asp:Label>
                </td>
                <td>
                    <asp:TextBox ID="txtGas_Pressure" runat="server"></asp:TextBox>
                </td>
            </tr>

            <tr>
                <td style="width: 200px">
                    <asp:Label ID="lblFeed_rate" runat="server" AssociatedControlID="txtFeed_rate" Text="Feed rate :"></asp:Label>
                </td>
                <td>
                    <asp:TextBox ID="txtFeed_rate" runat="server"></asp:TextBox>
                </td>
            </tr>

            <tr>
                <td style="width: 200px">
                    <asp:Label ID="lblTotal_Output_Product" runat="server" AssociatedControlID="txtTotal_Output_Product" Text="Total Output Product  :"></asp:Label>
                </td>
                <td>
                    <asp:TextBox ID="txtTotal_Output_Product" runat="server"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <button type="button" class="btn btn-default btn-xs" onclick="addRow('mytable2');"><span class="glyphicon glyphicon-plus"></span>Add Row</button>
                    <table id="mytable2" cellpadding="0" cellspacing="0">
                        <tr>
                            <td style="width: 170px">
                                <asp:Label ID="lblBag_Drum_Output" runat="server" AssociatedControlID="ddlBag_Drum_Output" Text="DRUM/BAG"></asp:Label>
                            </td>
                            <td>
                                <asp:Label ID="lblBag_Drum_Output_Num" runat="server" AssociatedControlID="txtBag_Drum_Output_Num" Text="DRUM/BAG #"></asp:Label>
                            </td>
                            <td></td>
                        </tr>
                        <tr>
                            <td style="width: 170px">
                                <asp:DropDownList ID="ddlBag_Drum_Output" runat="server" DataSourceID="Ds_Bag_Drum" DataTextField="VESSEL_TYPE" DataValueField="VESSEL_ID" OnDataBound="ddlBag_Drum_Output_DataBound">
                                </asp:DropDownList>
                                <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="selectAll" TypeName="DAL_tbl_vessel_master"></asp:ObjectDataSource>
                            </td>
                            <td>
                                <asp:TextBox ID="txtBag_Drum_Output_Num" runat="server"></asp:TextBox>
                            </td>
                            <td>
                                <button type="button" class="btn btn-default btn-xs" onclick="removeRow(this);"><span class="glyphicon glyphicon-remove"></span></button>
                            </td>
                        </tr>
                    </table>

                </td>
            </tr>


            <tr>
                <td style="width: 200px">
                    <asp:Label ID="lblDate" runat="server" AssociatedControlID="txtDate" Text="Date:"></asp:Label>
                </td>
                <td>
                    <asp:TextBox ID="txtDate" runat="server" type="date"></asp:TextBox>
                </td>
            </tr>



            <tr>
                <td style="width: 200px">&nbsp;</td>
                <td>

                    <input type="button" value="Save" style="width: 90px" class="btn btn-success" onclick="save();" />
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <asp:Button ID="btnCancel" runat="server" CssClass="btn btn-danger" Text="Cancel" Width="90px" />

                </td>
            </tr>

        </table>
        <asp:HiddenField ID="hdValue" runat="server" Value="1" />
    </asp:Panel>

</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="Grid" runat="Server">

    <asp:Panel ID="pnlList" runat="server">
        <asp:GridView ID="gridClients" runat="server" AutoGenerateColumns="False" CssClass="resTbl" DataSourceID="DS_tbl_sicomill">
            <Columns>
                <asp:BoundField DataField="PO_Number" HeaderText="PO Number " SortExpression="PO_Number" />
                <asp:BoundField DataField="Work_Order_Number" HeaderText="Work Order # " SortExpression="Work_Order_Number" />
                <asp:BoundField DataField="Total_Input_RM_Si" HeaderText="Total Input RM Si (in Kg) " SortExpression="Total_Input_RM_Si" />
                <asp:BoundField DataField="Mill_Selection" HeaderText="Mill Selection " SortExpression="Mill_Selection" />
                <asp:BoundField DataField="Rotor_RPM" HeaderText="Rotor RPM " SortExpression="Rotor_RPM" />
                <asp:BoundField DataField="Gas_Pressure" HeaderText="Gas Pressure " SortExpression="Gas_Pressure" />
                <asp:BoundField DataField="Feed_rate" HeaderText="Feed rate " SortExpression="Feed_rate" />
                <asp:BoundField DataField="Total_Output_Product" HeaderText="Total Output Product  " SortExpression="Total_Output_Product" />
                <asp:BoundField DataField="Date" HeaderText="Date  " SortExpression="Date" DataFormatString="{0:yyMMdd}" />
                <asp:BoundField DataField="CREATED_BY" HeaderText="Created By" SortExpression="CREATED_BY" />
                <asp:BoundField DataField="CREATED_DATE" HeaderText="Created Date" SortExpression="CREATED_DATE" DataFormatString="{0:yyMMdd}" />

                <asp:TemplateField HeaderText="Edit">
                    <ItemTemplate>
                        <asp:LinkButton ID="linkEdit" runat="server" Text="Edit" CommandArgument='<%# Eval("ID") %>' OnClick="linkEdit_Click"></asp:LinkButton>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Delete">
                    <ItemTemplate>
                        <asp:LinkButton ID="linkDelete" CommandName="delete" runat="server" Text="Delete" OnClientClick="javascript:return confirm('Are you sure you want to delete this record?');" CommandArgument='<%# Eval("ID") %>' OnClick="linkDelete_Click"></asp:LinkButton>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
        <asp:ObjectDataSource ID="DS_tbl_sicomill" runat="server" SelectMethod="selectAllForGrid" DeleteMethod="delete" InsertMethod="insert" UpdateMethod="update" TypeName="DAL_tbl_sicomill">
            <DeleteParameters>
                <asp:Parameter Name="ID" Type="Int32" />
            </DeleteParameters>
            <InsertParameters>
                <asp:Parameter Name="PO_Number" Type="String" />
                <asp:Parameter Name="Work_Order_Number" Type="String" />
                <asp:Parameter Name="Total_Input_RM_Si" Type="Decimal" />
                <asp:Parameter Name="Mill_Selection" Type="Int32" />
                <asp:Parameter Name="Rotor_RPM" Type="Decimal" />
                <asp:Parameter Name="Gas_Pressure" Type="Decimal" />
                <asp:Parameter Name="Feed_rate" Type="Decimal" />
                <asp:Parameter Name="Total_Output_Product" Type="Decimal" />
                <asp:Parameter Name="Date" Type="DateTime" />
                <asp:Parameter Name="CREATED_BY" Type="String" />
                <asp:Parameter Name="CREATED_DATE" Type="DateTime" />
            </InsertParameters>
            <UpdateParameters>
                <asp:Parameter Name="PO_Number" Type="String" />
                <asp:Parameter Name="Work_Order_Number" Type="String" />
                <asp:Parameter Name="Total_Input_RM_Si" Type="Decimal" />
                <asp:Parameter Name="Mill_Selection" Type="Int32" />
                <asp:Parameter Name="Rotor_RPM" Type="Decimal" />
                <asp:Parameter Name="Gas_Pressure" Type="Decimal" />
                <asp:Parameter Name="Feed_rate" Type="Decimal" />
                <asp:Parameter Name="Total_Output_Product" Type="Decimal" />
                <asp:Parameter Name="Date" Type="DateTime" />
                <asp:Parameter Name="UPDATED_BY" Type="String" />
                <asp:Parameter Name="UPDATED_DATE" Type="DateTime" />
            </UpdateParameters>
        </asp:ObjectDataSource>
    </asp:Panel>
</asp:Content>

